home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d21
/
dvcron10.arc
/
GETOPT.C
< prev
next >
Wrap
Text File
|
1991-12-21
|
856b
|
45 lines
/*
copyright (c) 1991 -- kyle a. york
use / copy / modify at will: please see CRON.DOC for details
*/
#include <alloc.h>
#include <stdio.h>
#include "getopt.h"
/*
getopt.c
return any switches found in the command string
each letter == a legal switch, a ':' following a letter means
that a number should follow
*/
int optind=0;
char *optarg=NULL;
int getopt(int argc, char **argv, char *optstring)
{
char *ptr;
if (!optind)
optind=1;
if ((optind > argc) || (argv[optind][0] != '-'))
return(EOF);
for (ptr=optstring; argv[optind][1] != *ptr; ptr++);
if (!*ptr)
return('?');
if (*(ptr+1) == ':') {
if (argv[optind][2])
optarg=argv[optind]+2;
else {
optarg=argv[optind+1];
optind++;
}
} else
optarg=NULL;
optind++;
return(*ptr);
}